﻿@model CustomerBackInStockSubscriptionsModel

@using SmartStore.Web;
@using SmartStore.Web.Models.Customer;
@using SmartStore.Web.Framework.UI;

@{    
	Html.AddTitleParts(T("PageTitle.BackInStockSubscriptions").Text);

	Layout = "_MyAccount";
	ViewBag.PageClassToken = "backinstock";
	ViewBag.PageTitle = T("Account.BackInStockSubscriptions").Text;
}

@if (Model.Subscriptions.Count == 0)
{
	<div class="alert alert-warning">
		@T("Account.BackInStockSubscriptions.NoSubscriptions")
	</div>
	return;
}

<div class="alert alert-success mb-0">
    @T("Account.BackInStockSubscriptions.Description")
</div>
       
@using (Html.BeginForm())
{
	<div class="subscription-list table-responsive">
		<table class="table">
			<thead>
				<tr>
					<th style="width: 30px">
						<input type="checkbox" id="selectall" />
					</th>
					<th>
						@T("Account.BackInStockSubscriptions.ProductColumn")
					</th>
				</tr>
			</thead>
			<tbody>
				@for (int i = 0; i < Model.Subscriptions.Count; i++)
				{
					var item = Model.Subscriptions[i];
					<tr>
						<td style="width: 30px">
							<input type="checkbox" name="biss@(item.Id)" class="rowcheckbox" />
						</td>
						<td @Html.LanguageAttributes(item.ProductName)>
							@Html.RouteLink(item.ProductName, "Product", new { SeName = item.SeName })
						</td>
					</tr>
				}
			</tbody>
		</table>

		@if (Model.TotalPages > 1)
		{
			@Html.SmartStore().Pager(Model).Name("paginator").QueryParam("page").Action("BackInStockSubscriptions", "Customer")
		}

		<div class="buttons">
			<button type="submit" class="btn btn-danger btn-lg delete-selected-biss-button">
                <span>@T("Account.BackInStockSubscriptions.DeleteSelected")</span>
			</button>
		</div>
	</div>
}

<script>
    $(function () {
    	$('#selectall').on('click', function (e) {
    		$('.subscription-list .rowcheckbox').attr('checked', $(this).is(':checked')).change();
    	});

    	$(document).on('change', '.subscription-list .rowcheckbox', function (e) {
    		var numChkBoxes = $('.subscription-list .rowcheckbox').length;
    		var numChkBoxesChecked = $('.subscription-list .rowcheckbox:checked').length;
    		$('#selectall').attr('checked', numChkBoxes == numChkBoxesChecked && numChkBoxes > 0);
    	});
    });
</script> 
